/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.railway.reports;

import com.railway.reports.utils.QueryBuilder;
import com.railway.utils.CustomScrollBarUI;
import java.util.List;

/**
 *
 * @author Kenny
 */
public class RedemptionCustomizer extends javax.swing.JPanel {

    private QueryBuilder qb;
    private int initialHave = 0;
    private boolean type = false;
    private boolean value = false;
    private boolean point = false;

    /**
     * Creates new form RedemptionCustomizer
     */
    public RedemptionCustomizer() {
        initComponents();
    }

    public boolean isSummaryReport() {
        return jrbSumReport.isSelected();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbgReportType = new javax.swing.ButtonGroup();
        jbgValue = new javax.swing.ButtonGroup();
        jbgPoints = new javax.swing.ButtonGroup();
        jbgException = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jlblRedemptionCustomizer = new javax.swing.JLabel();
        jsprCustomizer = new javax.swing.JSeparator();
        jrbSumReport = new javax.swing.JRadioButton();
        jrbExpReport = new javax.swing.JRadioButton();
        jcbItemType = new javax.swing.JCheckBox();
        jspItemType = new javax.swing.JScrollPane();
        jltItemType = new javax.swing.JList();
        jcbValue = new javax.swing.JCheckBox();
        jrbValueMore = new javax.swing.JRadioButton();
        jspiValueMore = new javax.swing.JSpinner();
        jrbValueLess = new javax.swing.JRadioButton();
        jspiValueLess = new javax.swing.JSpinner();
        jrbValueEquals = new javax.swing.JRadioButton();
        jspiValueEquals = new javax.swing.JSpinner();
        jcbPointRequired = new javax.swing.JCheckBox();
        jrbPointMore = new javax.swing.JRadioButton();
        jrbPointLess = new javax.swing.JRadioButton();
        jrbPointEquals = new javax.swing.JRadioButton();
        jspiPointEquals = new javax.swing.JSpinner();
        jspiPointLess = new javax.swing.JSpinner();
        jspiPointMore = new javax.swing.JSpinner();
        jrbRedeemTimes = new javax.swing.JRadioButton();
        jspiRefeemTimes = new javax.swing.JSpinner();
        jlblRedeemTimes = new javax.swing.JLabel();
        jrbMostPop = new javax.swing.JRadioButton();
        jlblPopTop = new javax.swing.JLabel();
        jspiMostPop = new javax.swing.JSpinner();
        jlblPopItem = new javax.swing.JLabel();
        jrbMostUnpop = new javax.swing.JRadioButton();
        jlblUnpopItem = new javax.swing.JLabel();
        jspiMostUnpop = new javax.swing.JSpinner();
        jlblUnpopTop = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        jScrollPane1.getVerticalScrollBar().setUI(new CustomScrollBarUI());
        jScrollPane1.getVerticalScrollBar().setUnitIncrement(16);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setPreferredSize(new java.awt.Dimension(198, 450));
        jPanel1.setLayout(null);

        jlblRedemptionCustomizer.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlblRedemptionCustomizer.setText("CRITERIA CUSTOMIZER");
        jPanel1.add(jlblRedemptionCustomizer);
        jlblRedemptionCustomizer.setBounds(10, 5, 200, 20);
        jPanel1.add(jsprCustomizer);
        jsprCustomizer.setBounds(5, 25, 200, 5);

        jrbSumReport.setBackground(new java.awt.Color(255, 255, 255));
        jbgReportType.add(jrbSumReport);
        jrbSumReport.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbSumReport.setSelected(true);
        jrbSumReport.setText("Summary/Details Report");
        jrbSumReport.setActionCommand("sum");
        jrbSumReport.setFocusPainted(false);
        jrbSumReport.setOpaque(false);
        jrbSumReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbSumReportActionPerformed(evt);
            }
        });
        jPanel1.add(jrbSumReport);
        jrbSumReport.setBounds(10, 30, 180, 20);

        jrbExpReport.setBackground(new java.awt.Color(255, 255, 255));
        jbgReportType.add(jrbExpReport);
        jrbExpReport.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbExpReport.setText("Exception Report");
        jrbExpReport.setActionCommand("exc");
        jrbExpReport.setOpaque(false);
        jrbExpReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbExpReportActionPerformed(evt);
            }
        });
        jPanel1.add(jrbExpReport);
        jrbExpReport.setBounds(10, 290, 180, 23);

        jcbItemType.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jcbItemType.setText("Item type");
        jcbItemType.setOpaque(false);
        jcbItemType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbItemTypeActionPerformed(evt);
            }
        });
        jPanel1.add(jcbItemType);
        jcbItemType.setBounds(20, 50, 160, 20);

        jspItemType.getVerticalScrollBar().setUI(new CustomScrollBarUI());

        jltItemType.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jltItemType.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Coupon", "Credit", "Souvenir" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jltItemType.setEnabled(false);
        jspItemType.setViewportView(jltItemType);

        jPanel1.add(jspItemType);
        jspItemType.setBounds(30, 70, 150, 55);

        jcbValue.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jcbValue.setText("Value");
        jcbValue.setOpaque(false);
        jcbValue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbValueActionPerformed(evt);
            }
        });
        jPanel1.add(jcbValue);
        jcbValue.setBounds(20, 130, 160, 20);

        jbgValue.add(jrbValueMore);
        jrbValueMore.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbValueMore.setSelected(true);
        jrbValueMore.setText("More than");
        jrbValueMore.setActionCommand("m");
        jrbValueMore.setEnabled(false);
        jrbValueMore.setOpaque(false);
        jrbValueMore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbValueMoreActionPerformed(evt);
            }
        });
        jPanel1.add(jrbValueMore);
        jrbValueMore.setBounds(30, 150, 90, 20);

        jspiValueMore.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiValueMore.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiValueMore.setEnabled(false);
        jPanel1.add(jspiValueMore);
        jspiValueMore.setBounds(120, 150, 60, 20);

        jbgValue.add(jrbValueLess);
        jrbValueLess.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbValueLess.setText("Less than");
        jrbValueLess.setActionCommand("l");
        jrbValueLess.setEnabled(false);
        jrbValueLess.setOpaque(false);
        jrbValueLess.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbValueLessActionPerformed(evt);
            }
        });
        jPanel1.add(jrbValueLess);
        jrbValueLess.setBounds(30, 190, 90, 20);

        jspiValueLess.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiValueLess.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiValueLess.setEnabled(false);
        jPanel1.add(jspiValueLess);
        jspiValueLess.setBounds(120, 190, 60, 22);

        jbgValue.add(jrbValueEquals);
        jrbValueEquals.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbValueEquals.setText("Equals to");
        jrbValueEquals.setActionCommand("e");
        jrbValueEquals.setEnabled(false);
        jrbValueEquals.setOpaque(false);
        jrbValueEquals.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbValueEqualsActionPerformed(evt);
            }
        });
        jPanel1.add(jrbValueEquals);
        jrbValueEquals.setBounds(30, 170, 90, 20);

        jspiValueEquals.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiValueEquals.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiValueEquals.setEnabled(false);
        jPanel1.add(jspiValueEquals);
        jspiValueEquals.setBounds(120, 170, 60, 22);

        jcbPointRequired.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jcbPointRequired.setText("Point required to redeem");
        jcbPointRequired.setOpaque(false);
        jcbPointRequired.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPointRequiredActionPerformed(evt);
            }
        });
        jPanel1.add(jcbPointRequired);
        jcbPointRequired.setBounds(20, 210, 170, 20);

        jbgPoints.add(jrbPointMore);
        jrbPointMore.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbPointMore.setSelected(true);
        jrbPointMore.setText("More than");
        jrbPointMore.setActionCommand("m");
        jrbPointMore.setEnabled(false);
        jrbPointMore.setOpaque(false);
        jrbPointMore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbPointMoreActionPerformed(evt);
            }
        });
        jPanel1.add(jrbPointMore);
        jrbPointMore.setBounds(30, 230, 90, 20);

        jbgPoints.add(jrbPointLess);
        jrbPointLess.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbPointLess.setText("Less than");
        jrbPointLess.setActionCommand("l");
        jrbPointLess.setEnabled(false);
        jrbPointLess.setOpaque(false);
        jrbPointLess.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbPointLessActionPerformed(evt);
            }
        });
        jPanel1.add(jrbPointLess);
        jrbPointLess.setBounds(30, 270, 90, 20);

        jbgPoints.add(jrbPointEquals);
        jrbPointEquals.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbPointEquals.setText("Equals to");
        jrbPointEquals.setActionCommand("e");
        jrbPointEquals.setEnabled(false);
        jrbPointEquals.setOpaque(false);
        jrbPointEquals.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbPointEqualsActionPerformed(evt);
            }
        });
        jPanel1.add(jrbPointEquals);
        jrbPointEquals.setBounds(30, 250, 90, 20);

        jspiPointEquals.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiPointEquals.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiPointEquals.setEnabled(false);
        jPanel1.add(jspiPointEquals);
        jspiPointEquals.setBounds(120, 250, 60, 20);

        jspiPointLess.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiPointLess.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiPointLess.setEnabled(false);
        jPanel1.add(jspiPointLess);
        jspiPointLess.setBounds(120, 270, 60, 20);

        jspiPointMore.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiPointMore.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiPointMore.setEnabled(false);
        jPanel1.add(jspiPointMore);
        jspiPointMore.setBounds(120, 230, 60, 20);

        jbgException.add(jrbRedeemTimes);
        jrbRedeemTimes.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbRedeemTimes.setSelected(true);
        jrbRedeemTimes.setText("Item redeemed times");
        jrbRedeemTimes.setActionCommand("iri");
        jrbRedeemTimes.setEnabled(false);
        jrbRedeemTimes.setOpaque(false);
        jrbRedeemTimes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbRedeemTimesActionPerformed(evt);
            }
        });
        jPanel1.add(jrbRedeemTimes);
        jrbRedeemTimes.setBounds(20, 310, 160, 20);

        jspiRefeemTimes.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiRefeemTimes.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiRefeemTimes.setEnabled(false);
        jPanel1.add(jspiRefeemTimes);
        jspiRefeemTimes.setBounds(40, 330, 40, 22);

        jlblRedeemTimes.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jlblRedeemTimes.setText("or more times");
        jlblRedeemTimes.setEnabled(false);
        jPanel1.add(jlblRedeemTimes);
        jlblRedeemTimes.setBounds(85, 330, 90, 20);

        jbgException.add(jrbMostPop);
        jrbMostPop.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbMostPop.setText("Most popular item");
        jrbMostPop.setActionCommand("mpi");
        jrbMostPop.setEnabled(false);
        jrbMostPop.setOpaque(false);
        jrbMostPop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbMostPopActionPerformed(evt);
            }
        });
        jPanel1.add(jrbMostPop);
        jrbMostPop.setBounds(20, 350, 160, 23);

        jlblPopTop.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jlblPopTop.setText("Top");
        jlblPopTop.setEnabled(false);
        jPanel1.add(jlblPopTop);
        jlblPopTop.setBounds(45, 370, 30, 20);

        jspiMostPop.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiMostPop.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiMostPop.setToolTipText("Zero to diisplay all");
        jspiMostPop.setEnabled(false);
        jPanel1.add(jspiMostPop);
        jspiMostPop.setBounds(70, 370, 40, 22);

        jlblPopItem.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jlblPopItem.setText("Items");
        jlblPopItem.setEnabled(false);
        jPanel1.add(jlblPopItem);
        jlblPopItem.setBounds(115, 370, 50, 20);

        jbgException.add(jrbMostUnpop);
        jrbMostUnpop.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jrbMostUnpop.setText("Most unpopular item");
        jrbMostUnpop.setActionCommand("mui");
        jrbMostUnpop.setEnabled(false);
        jrbMostUnpop.setOpaque(false);
        jrbMostUnpop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbMostUnpopActionPerformed(evt);
            }
        });
        jPanel1.add(jrbMostUnpop);
        jrbMostUnpop.setBounds(20, 390, 170, 23);

        jlblUnpopItem.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jlblUnpopItem.setText("Items");
        jlblUnpopItem.setEnabled(false);
        jPanel1.add(jlblUnpopItem);
        jlblUnpopItem.setBounds(115, 410, 50, 20);

        jspiMostUnpop.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jspiMostUnpop.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        jspiMostUnpop.setToolTipText("Zero to diisplay all");
        jspiMostUnpop.setEnabled(false);
        jPanel1.add(jspiMostUnpop);
        jspiMostUnpop.setBounds(70, 410, 40, 20);

        jlblUnpopTop.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jlblUnpopTop.setText("Top");
        jlblUnpopTop.setEnabled(false);
        jPanel1.add(jlblUnpopTop);
        jlblUnpopTop.setBounds(45, 410, 30, 20);

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 561, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jrbSumReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbSumReportActionPerformed
        jcbItemType.setEnabled(true);
        jcbValue.setEnabled(true);
        jcbPointRequired.setEnabled(true);
        jrbMostPop.setEnabled(false);
        jrbMostUnpop.setEnabled(false);
        jrbRedeemTimes.setEnabled(false);
        jspiRefeemTimes.setEnabled(false);
        jlblRedeemTimes.setEnabled(false);
        jspiMostPop.setEnabled(false);
        jlblPopTop.setEnabled(false);
        jlblPopItem.setEnabled(false);
        jspiMostUnpop.setEnabled(false);
        jlblUnpopTop.setEnabled(false);
        jlblUnpopItem.setEnabled(false);
    }//GEN-LAST:event_jrbSumReportActionPerformed

    private void jrbExpReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbExpReportActionPerformed
        jcbItemType.setEnabled(false);
        jcbValue.setEnabled(false);
        jcbPointRequired.setEnabled(false);
        jrbMostPop.setEnabled(true);
        jrbMostUnpop.setEnabled(true);
        jrbRedeemTimes.setEnabled(true);
        jspiRefeemTimes.setEnabled(true);
    }//GEN-LAST:event_jrbExpReportActionPerformed

    private void jcbItemTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbItemTypeActionPerformed
        if (jcbItemType.isSelected()) {
            type = true;
            jltItemType.setSelectedIndex(0);
            jltItemType.setEnabled(true);
        } else {
            type = false;
            jltItemType.clearSelection();
            jltItemType.setEnabled(false);
        }
    }//GEN-LAST:event_jcbItemTypeActionPerformed

    private void jcbValueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbValueActionPerformed
        if (jcbValue.isSelected()) {
            value = true;
            jrbValueMore.setEnabled(true);
            jspiValueMore.setEnabled(true);
            jrbValueEquals.setEnabled(true);
            jrbValueLess.setEnabled(true);
        } else {
            value = false;
            jrbValueMore.setEnabled(false);
            jspiValueMore.setEnabled(false);
            jrbValueEquals.setEnabled(false);
            jspiValueEquals.setEnabled(false);
            jrbValueLess.setEnabled(false);
            jspiValueLess.setEnabled(false);
        }
    }//GEN-LAST:event_jcbValueActionPerformed

    private void jcbPointRequiredActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPointRequiredActionPerformed
        if (jcbPointRequired.isSelected()) {
            point = true;
            jrbPointMore.setEnabled(true);
            jspiPointMore.setEnabled(true);
            jrbPointEquals.setEnabled(true);
            jrbPointLess.setEnabled(true);
        } else {
            point = false;
            jrbPointMore.setEnabled(false);
            jspiPointMore.setEnabled(false);
            jrbPointEquals.setEnabled(false);
            jspiPointEquals.setEnabled(false);
            jrbPointLess.setEnabled(false);
            jspiPointLess.setEnabled(false);
        }
    }//GEN-LAST:event_jcbPointRequiredActionPerformed

    private void jrbValueMoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbValueMoreActionPerformed
        jspiValueMore.setEnabled(true);
        jspiValueEquals.setEnabled(false);
        jspiValueLess.setEnabled(false);
    }//GEN-LAST:event_jrbValueMoreActionPerformed

    private void jrbValueLessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbValueLessActionPerformed
        jspiValueMore.setEnabled(false);
        jspiValueEquals.setEnabled(false);
        jspiValueLess.setEnabled(true);
    }//GEN-LAST:event_jrbValueLessActionPerformed

    private void jrbValueEqualsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbValueEqualsActionPerformed
        jspiValueMore.setEnabled(false);
        jspiValueEquals.setEnabled(true);
        jspiValueLess.setEnabled(false);
    }//GEN-LAST:event_jrbValueEqualsActionPerformed

    private void jrbPointMoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbPointMoreActionPerformed
        jspiPointMore.setEnabled(true);
        jspiPointEquals.setEnabled(false);
        jspiPointLess.setEnabled(false);
    }//GEN-LAST:event_jrbPointMoreActionPerformed

    private void jrbPointEqualsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbPointEqualsActionPerformed
        jspiPointMore.setEnabled(false);
        jspiPointEquals.setEnabled(true);
        jspiPointLess.setEnabled(false);
    }//GEN-LAST:event_jrbPointEqualsActionPerformed

    private void jrbPointLessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbPointLessActionPerformed
        jspiPointMore.setEnabled(false);
        jspiPointEquals.setEnabled(false);
        jspiPointLess.setEnabled(true);
    }//GEN-LAST:event_jrbPointLessActionPerformed

    private void jrbRedeemTimesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbRedeemTimesActionPerformed
        jspiRefeemTimes.setEnabled(true);
        jlblRedeemTimes.setEnabled(true);
        jspiMostPop.setEnabled(false);
        jlblPopTop.setEnabled(false);
        jlblPopItem.setEnabled(false);
        jspiMostUnpop.setEnabled(false);
        jlblUnpopTop.setEnabled(false);
        jlblUnpopItem.setEnabled(false);
    }//GEN-LAST:event_jrbRedeemTimesActionPerformed

    private void jrbMostPopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbMostPopActionPerformed
        jspiRefeemTimes.setEnabled(false);
        jlblRedeemTimes.setEnabled(false);
        jspiMostPop.setEnabled(true);
        jlblPopTop.setEnabled(true);
        jlblPopItem.setEnabled(true);
        jspiMostUnpop.setEnabled(false);
        jlblUnpopTop.setEnabled(false);
        jlblUnpopItem.setEnabled(false);
    }//GEN-LAST:event_jrbMostPopActionPerformed

    private void jrbMostUnpopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbMostUnpopActionPerformed
        jspiRefeemTimes.setEnabled(false);
        jlblRedeemTimes.setEnabled(false);
        jspiMostPop.setEnabled(false);
        jlblPopTop.setEnabled(false);
        jlblPopItem.setEnabled(false);
        jspiMostUnpop.setEnabled(true);
        jlblUnpopTop.setEnabled(true);
        jlblUnpopItem.setEnabled(true);
    }//GEN-LAST:event_jrbMostUnpopActionPerformed

    private void typeWhere() {
        List<String> typeList = jltItemType.getSelectedValuesList();
        qb.where("itemType", typeList.get(0), true);
        for (int i = 1; i < typeList.size(); i++) {
            qb.or("itemType", typeList.get(i));
        }
    }

    private void valueHaving() {
        String operator = jbgValue.getSelection().getActionCommand();
        switch (operator) {
            case "m":
                qb.having("value", (int) jspiValueMore.getValue(), QueryBuilder.MORE_THAN);
                break;
            case "e":
                qb.having("value", (int) jspiValueEquals.getValue());
                break;
            case "l":
                qb.having("value", (int) jspiValueLess.getValue(), QueryBuilder.LESS_THAN);
                break;
        }
    }

    private void valueAnd() {
        String operator = jbgValue.getSelection().getActionCommand();
        switch (operator) {
            case "m":
                qb.and("value", (int) jspiValueMore.getValue(), QueryBuilder.MORE_THAN);
                break;
            case "e":
                qb.and("value", (int) jspiValueEquals.getValue());
                break;
            case "l":
                qb.and("value", (int) jspiValueLess.getValue(), QueryBuilder.LESS_THAN);
                break;
        }
    }

    private void pointHaving() {
        String operator = jbgPoints.getSelection().getActionCommand();
        switch (operator) {
            case "m":
                qb.having("pointRequired", (int) jspiPointMore.getValue(), QueryBuilder.MORE_THAN);
                break;
            case "e":
                qb.having("pointRequired", (int) jspiPointEquals.getValue());
                break;
            case "l":
                qb.having("pointRequired", (int) jspiPointLess.getValue(), QueryBuilder.LESS_THAN);
                break;
        }
    }

    private void pointAnd() {
        String operator = jbgPoints.getSelection().getActionCommand();
        switch (operator) {
            case "m":
                qb.and("pointRequired", (int) jspiPointMore.getValue(), QueryBuilder.MORE_THAN);
                break;
            case "e":
                qb.and("pointRequired", (int) jspiPointEquals.getValue());
                break;
            case "l":
                qb.and("pointRequired", (int) jspiPointLess.getValue(), QueryBuilder.LESS_THAN);
                break;
        }
    }

    public String buildQuery() {
        qb = new QueryBuilder();
        initialHave = 0;
        if (isSummaryReport()) {
            qb.select("itemCode", "itemName", "pointRequired", "value", "itemType").from("redeemableitem");
            if (type) {
                initialHave = 1;
                typeWhere();
            }
            if (value) {
                if (initialHave != 1 && initialHave != 3) {
                    initialHave = 2;
                    valueHaving();
                } else {
                    if (initialHave == 1) {
                        valueHaving();
                    } else {
                        valueAnd();
                    }
                }
            }
            if (point) {
                if (initialHave != 1 && initialHave != 2) {
                    initialHave = 3;
                    pointHaving();
                } else {
                    if (initialHave == 1 && !value) {
                        pointHaving();
                    } else {
                        pointAnd();
                    }
                }
            }
        } else {
            qb.select("ri.itemCode", "itemName", "itemType", "pointRequired", "value", "COUNT(rd.itemCode) AS times").from("redeemableitem ri LEFT JOIN redeemeditem rd ON rd.itemCode = ri.itemCode GROUP BY 1");
            String action = jbgException.getSelection().getActionCommand();
            int number;
            switch (action) {
                case "iri":
                    qb.having("times", (int)jspiRefeemTimes.getValue(), QueryBuilder.MORE_THAN_EQUALS);
                    qb.orderBy("times", QueryBuilder.DESC, true);
                    break;
                case "mpi":
                    qb.orderBy("times", QueryBuilder.DESC, true);
                    number = (int)jspiMostPop.getValue();
                    if(number != 0){
                        qb.limit(number);
                    }
                    break;
                case "mui":
                    qb.orderBy("times", QueryBuilder.ASC, true);
                    number = (int)jspiMostUnpop.getValue();
                    if(number != 0){
                        qb.limit(number);
                    }
                    break;
            }
        }
        return qb.build();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.ButtonGroup jbgException;
    private javax.swing.ButtonGroup jbgPoints;
    private javax.swing.ButtonGroup jbgReportType;
    private javax.swing.ButtonGroup jbgValue;
    private javax.swing.JCheckBox jcbItemType;
    private javax.swing.JCheckBox jcbPointRequired;
    private javax.swing.JCheckBox jcbValue;
    private javax.swing.JLabel jlblPopItem;
    private javax.swing.JLabel jlblPopTop;
    private javax.swing.JLabel jlblRedeemTimes;
    private javax.swing.JLabel jlblRedemptionCustomizer;
    private javax.swing.JLabel jlblUnpopItem;
    private javax.swing.JLabel jlblUnpopTop;
    private javax.swing.JList jltItemType;
    private javax.swing.JRadioButton jrbExpReport;
    private javax.swing.JRadioButton jrbMostPop;
    private javax.swing.JRadioButton jrbMostUnpop;
    private javax.swing.JRadioButton jrbPointEquals;
    private javax.swing.JRadioButton jrbPointLess;
    private javax.swing.JRadioButton jrbPointMore;
    private javax.swing.JRadioButton jrbRedeemTimes;
    private javax.swing.JRadioButton jrbSumReport;
    private javax.swing.JRadioButton jrbValueEquals;
    private javax.swing.JRadioButton jrbValueLess;
    private javax.swing.JRadioButton jrbValueMore;
    private javax.swing.JScrollPane jspItemType;
    private javax.swing.JSpinner jspiMostPop;
    private javax.swing.JSpinner jspiMostUnpop;
    private javax.swing.JSpinner jspiPointEquals;
    private javax.swing.JSpinner jspiPointLess;
    private javax.swing.JSpinner jspiPointMore;
    private javax.swing.JSpinner jspiRefeemTimes;
    private javax.swing.JSpinner jspiValueEquals;
    private javax.swing.JSpinner jspiValueLess;
    private javax.swing.JSpinner jspiValueMore;
    private javax.swing.JSeparator jsprCustomizer;
    // End of variables declaration//GEN-END:variables
}
